//common scripts
function checkAll(checker) {
	oChecks = document.getElementsByName("ids");
	var i = oChecks.length;
	while (i != 0) {
		var oCheckbox = oChecks[i - 1];
		if (oCheckbox.disabled){
			i--;
			continue;
		}
		
		if (checker.checked) {
			oCheckbox.checked = true;
		} else {
			oCheckbox.checked = false;
		}
		i--;
	}

}

/*
 * function setChecks(){ oTables = document.getElementsByTagName("table"); if
 * (oTables==null || oTables.length==0){return;} oTable = oTables[0]; var i =
 * oTable.rows.length; while (i != 0){ var oCheckbox =
 * document.createElement("input"); oCheckbox.type = "checkbox";
 * oTable.rows[i-1].insertCell(0);
 * oTable.rows[i-1].cells[0].appendChild(oCheckbox); i--; }
 *  }
 */

function setPageLinks() {
	var pagelinks = document.getElementById("pagelinks");
	if (pagelinks == null)
		return;
	var links = pagelinks.getElementsByTagName("a");
	var i = links.length;
	while (i != 0) {
		var oA = links[i - 1];
		var oHerf = oA.href;
		oA.href = encodeHref(oHerf);

		i--;
	}
}

function setSelected(selectQueryIds, paramFinder) {
	if (selectQueryIds.length == 0) {
		return;
	}

	var modelIds = selectQueryIds.split(",");
	var oSelects = document.getElementsByTagName("select");
	if (oSelects == null || oSelects.length != modelIds.length) {
		return;
	}

	var s = oSelects.length;
	while (s != 0) {
		var oSelect = oSelects[s - 1];

		addAllQueryOption(oSelect, selectQueryIds, paramFinder);
		var selectId = modelIds[s - 1];
		var i = oSelect.options.length;
		while (i != 0) {
			if (oSelect.options[i - 1].value == selectId) {
				oSelect.options[i - 1].setAttribute("selected", "selected");
				break;
			}
			i--;
		}
		s--;
	}
}

function addAllQueryOption(oSelect, selectQueryIds, paramFinder) {
	var allOption = document.createElement("option");
	allOption.appendChild(document.createTextNode("ALL"));
	if (paramFinder == "ByUsernameLikeAndAuthority" || selectQueryIds == "SUPERVISOR") {
		allOption.setAttribute("value", "SUPERVISOR");
	} else {
		allOption.setAttribute("value", -1);
	}
	oSelect.insertBefore(allOption, oSelect.options[0]);
}
